package com.app.micaihu.bean.news;

import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.Response;
import com.app.micaihu.R;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.micaihu.utils.HttpUtils;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;

/**
 * 小图视频
 * Created by linkai on 2016/7/17.
 */
public class ViewAboutVideoSmallImg extends ViewNewsParent {

    public CustomImageView smallImg;
    public View videoPic;
    public ImageView attrImg;//属性图片
    public TextView playCount;//播放次数
    public TextView period;//期数
//    public TextView laudNum;

    public ViewAboutVideoSmallImg(View convertView) {
        initView(convertView);
    }

    /**
     * 初始化控件
     *
     * @param convertView
     */
    public void initView(View convertView) {
        super.initView(convertView);
        this.smallImg = (CustomImageView) convertView.findViewById(R.id.item_small_image);
        this.videoPic = convertView.findViewById(R.id.item_video_pic);
        period = (TextView) convertView.findViewById(R.id.item_period);
        attrImg = (ImageView) convertView.findViewById(R.id.item_attricon);
        //用时间的控件显示播放次数
        publishTime = null;
        playCount = (TextView) convertView.findViewById(R.id.item_public_time);
//        this.laudNum = (TextView) convertView.findViewById(R.id.item_public_laud_count);
//        this.laudNum.setOnClickListener(this);
        ViewSizeUtils.changeViewAuto1080(this.smallImg, 324, 232);
        ViewSizeUtils.changeViewAuto1080(this.videoPic, 324, 232);
        convertView.setTag(this);
    }

    /**
     * 加载数据
     *
     * @param newsEntity
     */
    public void loadData(NewsEntity newsEntity) {
        super.loadData(newsEntity);
        if (newsEntity.getArticleThumb() != null && newsEntity.getArticleThumb().length > 0) {
            LoadImageUtils.getInstance().loadImage(this.smallImg, newsEntity.getArticleThumb()[0]);
        }

        if (TextUtils.isEmpty(newsEntity.getPeriod())
                && this.period.getVisibility() == View.VISIBLE) {
            this.period.setVisibility(View.GONE);
        } else if (!TextUtils.isEmpty(newsEntity.getPeriod())) {
            this.period.setText(newsEntity.getPeriod());
            if (this.period.getVisibility() == View.GONE) {
                this.period.setVisibility(View.VISIBLE);
            }
        }
        playCount.setText(newsEntity.getClickNum() + "播放");
        if (attrImg != null && TextUtils.isEmpty(newsEntity.getAttrIcon())) {
            if (this.attrImg.getVisibility() == View.VISIBLE) {
                this.attrImg.setVisibility(View.GONE);
            }
        } else {
            //加载图片
            HttpUtils.addImageRequest(newsEntity.getAttrIcon(), "", 0, 0, new Response.Listener<Bitmap>() {
                @Override
                public void onResponse(Bitmap response) {
                    if (response != null && attrImg != null) {
                        attrImg.setVisibility(View.VISIBLE);
                        attrImg.setImageBitmap(response);

                    }
                }
            }, null);
        }
//        this.laudNum.setText(newsEntity.getPraiseNum());
//        this.laudNum.setTag(R.id.tag_first, newsEntity.getArticleId());
//        this.laudNum.setSelected(newsEntity.IsPraise());
//        this.laudNum.setTag(newsEntity.IsPraise());
    }


//    @Override
//    public void onClick(View v) {
//        zan();
//    }

//    /**
//     * 点赞
//     */
//    private void zan(){
//        if(!UserInforManager.getInstance().isLogin()){
//            ToastUtils.makeText("请先登录");
//            return;
//        }
//        if(laudNum == null){
//            ToastUtils.makeText(R.drawable.handle_fail, "点赞失败");
//            return;
//        }
//        Object b =  laudNum.getTag();
//        int num = 0;
//        ParamMap parmsMap = new ParamMap();
//        try {
//            if(b != null && ((boolean)b)){
//                //如果已经点过赞 则取消点赞
//
//                laudNum.setSelected(false);
//                laudNum.setTag(false);
//                num = StringUtils.toInt(laudNum.getText().toString(), 0) - 1;
//                //取消赞参数
//                parmsMap.putEncode("operateType", "1");
//            } else {
//                //如果没有点赞 则进行点赞
//                laudNum.setSelected(true);
//                laudNum.setTag(true);
//                num = StringUtils.toInt(laudNum.getText().toString(), 0) + 1;
//                //点赞 参数
//                parmsMap.putEncode("operateType", "0");
//            }
//        } catch (Resources.NotFoundException e) {
//            e.printStackTrace();
//        }
//        if(num >= 0){
//            laudNum.setText(num+"");
//        }
//        //请求点赞网络操作
//        parmsMap.putEncode("uid", UserInforManager.getInstance().getUserInfor().getUid());
//        parmsMap.putEncode("type", "0");
//        parmsMap.putEncode("articleId",laudNum.getTag(R.id.tag_first).toString());
//        parmsMap.putEncode("toUid", "");
//        parmsMap.putEncode("commentId", "");
//        parmsMap.putEncode("parentCmtId", "");
//        HttpUtils.ParmsMapMD5(parmsMap);
//
//        HttpListener<DataBean> httpListener = new HttpListener<DataBean>() {
//            @Override
//            public void onError(VolleyError error) {
//                LogUtils.i("点赞---onError---");
//            }
//
//            @Override
//            public void onSuccess(DataBean response) {
//                LogUtils.i("点赞---onSuccess---");
//            }
//        };
//
//        //请求网络
//        HttpUtils.addPostRequest(URIContant.NEWS_ZAN, new TypeToken<DataBean>() {
//        }.getType(), null,parmsMap, httpListener);
//    }

}
